$(document).ready(function(){
	var count = 6;
	getEncrData(0,5);
	nextPage(count);
	prePage(count);
});

function setPage(start,end){

	$("#start").text(start);
	$("#end").text(end);
}

function isPaging(){
	var start = parseInt($("#start").text());
	var end = parseInt($("#end").text());
	if(start==0)
		$("#previous").hide();
	else
		$("#previous").show();

	if(end==0)
		$("#next").hide();
	else
		$("#next").show();
}

function prePage(count){
	$("#previous").click(function(){
		var start = $("#start").text();
		var end = $("#end").text();

		var t_start = parseInt(start);
		var t_end = parseInt(end);

		t_end = t_start-1;
		t_start = t_start-count;
		t_start = (t_start>=0)?t_start:0;
		t_end = (t_end>=t_start)?t_end:0;
		
		//设置标记
		setPage(t_start,t_end);
		//获取数据
		getEncrData(t_start,t_end);

	});
}

function nextPage(count){
	$("#next").click(function(){
		var start = $("#start").text();
		var end = $("#end").text();

		var t_start = parseInt(start);
		var t_end = parseInt(end);
		t_start = t_end+1;
		t_end = t_end+count;
		//设置标记
		setPage(t_start,t_end);
		//获取数据
		getEncrData(t_start,t_end);
		
	});
}
function getEncrData(start,end){
$.post(
		"127.0.0.1:8080/datacompute/getEncrData",
		{
			"start":start,
			"end":end
		},
		function(datas,status){
			var str = "<tr>";
			var data = datas.data; 
			for(i=0;i<data.length;i++){

					str +="<td>"+data[i].id+"</td>"+"<td>"+data[i].encrData+"</td>"+"<td>"+formatTime(data[i].timeMillis)+"</td>";
				
					str +="</tr>";
					
			}

			$("#tbody").html(str);
			var count = end-start+1;
			if(data.length<count)
				end=0;
			setPage(start,end);
			isPaging();
	});
}
function add0(m){return m<10?'0'+m:m }
function formatTime(timeMillis)
{
//shijianchuo是整数，否则要parseInt转换
var time = new Date(timeMillis);
var y = time.getFullYear();
var m = time.getMonth()+1;
var d = time.getDate();
var h = time.getHours();
var mm = time.getMinutes();
var s = time.getSeconds();
return y+'-'+add0(m)+'-'+add0(d)+' '+add0(h)+':'+add0(mm)+':'+add0(s);
}